summaryrefslogtreecommitdiffstats
path: root/src/core/hle/service/nvdrv/core/syncpoint_manager.h
blob: f332edc6e457d59940d0a16153d067fb6f6bb755 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// SPDX-FileCopyrightText: Copyright 2020 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later

#pragma once

#include <array>
#include <atomic>

#include "common/common_types.h"
#include "core/hle/service/nvdrv/nvdata.h"

namespace Tegra {

namespace Host1x {
class Host1x;
} // namespace Host1x

} // namespace Tegra

namespace Service::Nvidia::NvCore {

class SyncpointManager final {
public:
    explicit SyncpointManager(Tegra::Host1x::Host1x& host1x);
    ~SyncpointManager();

    /**
     * Returns true if the specified syncpoint is expired for the given value.
     * @param syncpoint_id Syncpoint ID to check.
     * @param value Value to check against the specified syncpoint.
     * @returns True if the specified syncpoint is expired for the given value, otherwise False.
     */
    bool IsSyncpointExpired(u32 syncpoint_id, u32 value) const {
        return (GetSyncpointMax(syncpoint_id) - value) >= (GetSyncpointMin(syncpoint_id) - value);
    }

    /**
     * Gets the lower bound for the specified syncpoint.
     * @param syncpoint_id Syncpoint ID to get the lower bound for.
     * @returns The lower bound for the specified syncpoint.
     */
    u32 GetSyncpointMin(u32 syncpoint_id) const {
        return syncpoints.at(syncpoint_id).min.load(std::memory_order_relaxed);
    }

    /**
     * Gets the uper bound for the specified syncpoint.
     * @param syncpoint_id Syncpoint ID to get the upper bound for.
     * @returns The upper bound for the specified syncpoint.
     */
    u32 GetSyncpointMax(u32 syncpoint_id) const {
        return syncpoints.at(syncpoint_id).max.load(std::memory_order_relaxed);
    }

    /**
     * Refreshes the minimum value for the specified syncpoint.
     * @param syncpoint_id Syncpoint ID to be refreshed.
     * @returns The new syncpoint minimum value.
     */
    u32 RefreshSyncpoint(u32 syncpoint_id);

    /**
     * Allocates a new syncoint.
     * @returns The syncpoint ID for the newly allocated syncpoint.
     */
    u32 AllocateSyncpoint();

    /**
     * Increases the maximum value for the specified syncpoint.
     * @param syncpoint_id Syncpoint ID to be increased.
     * @param value Value to increase the specified syncpoint by.
     * @returns The new syncpoint maximum value.
     */
    u32 IncreaseSyncpoint(u32 syncpoint_id, u32 value);

private:
    struct Syncpoint {
        std::atomic<u32> min;
        std::atomic<u32> max;
        std::atomic<bool> is_allocated;
    };

    std::array<Syncpoint, MaxSyncPoints> syncpoints{};

    Tegra::Host1x::Host1x& host1x;
};

} // namespace Service::Nvidia::NvCore